package com.ybxx.fees.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.StatementCallback;

import com.ybxx.base.model.FeesType;
import com.ybxx.core.command.QueryFilter;
import com.ybxx.core.dao.impl.BaseDaoImpl;
import com.ybxx.core.util.UUIDGenerator;
import com.ybxx.core.web.paging.PagingBean;
import com.ybxx.fees.dao.WsfRecordDao;
import com.ybxx.fees.model.AnmeterRecordItem;
import com.ybxx.fees.model.AnmeterRecords;
import com.ybxx.fees.model.WsfRecord;
import com.ybxx.fees.model.WsfRecordItem;

public class WsfRecordDaoImpl extends BaseDaoImpl<WsfRecord> implements
		WsfRecordDao {

	public WsfRecordDaoImpl() {
		super(WsfRecord.class);
		// TODO Auto-generated constructor stub
	}
	public WsfRecord generator(final String sql) {
		return super.jdbcTemplate.execute(new StatementCallback<WsfRecord>(){
			public WsfRecord doInStatement(Statement stat)
					throws SQLException, DataAccessException {
				ResultSet rs=stat.executeQuery(sql);
				WsfRecord wsfRecord=null;
				if(!rs.next()){
					return null;
				}
				wsfRecord=new WsfRecord();
				wsfRecord.setWsfrcode(UUIDGenerator.getUUID());
				
				float count=0.0f;
				do{
					WsfRecordItem item=new WsfRecordItem();
					item.setWicode(UUIDGenerator.getUUID());
					item.setFeesType(new FeesType(rs.getString("ftid")));
					item.setWsfRecord(wsfRecord);
					item.setRnum(rs.getString("rnum"));
					item.setYmoney(rs.getString("fees"));
					item.setPrice(rs.getString("price"));
					count=count+Float.parseFloat((item.getYmoney()==null || "".equals(item.getYmoney()))?"0":item.getYmoney());
					wsfRecord.getItems().add(item);
				}while(rs.next());
				wsfRecord.setReceivable(count+"");
				return wsfRecord;
			}
			
		});
	}
}
